class_name PlayerState
extends State

@onready var player: FightingPlayer = get_tree().get_first_node_in_group("player")

@export_group("States")
@export var idle_state: PlayerState
@export var walk_state: PlayerState
@export var jump_state: PlayerState
@export var fall_state: PlayerState

func is_movement_pressed(event: InputEvent) -> bool:
	for action in ["move_left", "move_right", "move_up", "move_down"]:
		if event.is_action_pressed(action):
			return true
	return false
		
func determine_player_flipped(event: InputEvent) -> void:
	if event.is_action_pressed("move_left") or event.is_action_pressed("move_right"):
		player.animated_sprite_2d.flip_h = event.is_action_pressed("move_left")

func get_move_dir() -> float:
	return Input.get_axis("move_left", "move_right")

func do_move(move_dir: float, speed: float) -> void:
	player.velocity.x = move_dir * speed

func process_physics(delta: float) -> State:
	if player.velocity.y < 0:
		return fall_state
	if not player.is_on_floor():
		player.velocity += player.get_gravity() * delta
	player.move_and_slide()
	return null
